from fabric import Connection
import tarfile
import os

os.system("cd .. && npm run build:prod && cd deploy")
with tarfile.open('../dist.tar', 'w') as tar:
    tar.add('../dist', arcname='dist')
c = Connection("root@121.5.109.215")
with c.cd('/root/rain/lamb-admin/deploy'):
    c.run("rm -rf ../dist", pty=True)
    c.put('./Dockerfile', '/root/rain/lamb-admin/deploy')
    c.put('./docker-compose.yml', '/root/rain/lamb-admin/deploy')
    c.put('./nginx.conf', '/root/rain/lamb-admin/deploy')
    c.put('./start.sh', '/root/rain/lamb-admin/deploy')
    c.put('../dist.tar', '/root/rain/lamb-admin')
    c.run("cd .. && tar xvf /root/rain/lamb-admin/dist.tar && cd deploy", pty=True)
    c.run("chmod 777 ./start.sh && ./start.sh", pty=True)
    c.run("docker ps", pty=True)
os.remove('../dist.tar')
